<?php
/*

Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/
include_once($semf_root.'page_designer/components/Component.php');

class LinkComponent extends Component
{
	private static $LINK_PARAM_PREFIX = "Link-Param";
	
	public static function get_properties()
	{
		return array(
					'DataBinding'=> array(
							'Text' => 'link1',
							'Title' => 'Link Title'),
					'Links'=> array(
							'Link' => '',
							'Parameter-Count'=> '0'),
					 );
	}

	
	/** build properties dynamically if atmost one property is changed*/
	public static function build_properties($parent_container, $properties, 
											$property_group, $key, $value)
	{
		if( $key != NULL )
		{
			$properties[$property_group][$key] = $value;
			if($key == 'Parameter-Count')
			{
				$count = $properties["Links"]["Parameter-Count"];
				$new_links = array();
				//copy two old values..
				$new_links["Link"] = $properties["Links"]["Link"];
				$new_links["Parameter-Count"] = $count;
				for($i = 1; $i <= $count; $i ++)
				{
					if($properties["Links"][LinkComponent::$LINK_PARAM_PREFIX.$i] == NULL)
					{
						$new_links[LinkComponent::$LINK_PARAM_PREFIX.$i] = "param".$i."=".$i;
					}
					else
					{
						$new_links[LinkComponent::$LINK_PARAM_PREFIX.$i] = $properties["Links"][LinkComponent::$LINK_PARAM_PREFIX.$i];
					}
				}
				$properties["Links"] = $new_links;
			}
		}
		return 	$properties;
	}
	
	
	public static function get_property_info($component_id, $properties)
	{
		return array('Text'=> array(
							'attri' => 'innerHTML', //that is to declare elem1.value should be set
							'databind' => "ln_".$component_id));
	}
	
	public static function get_link_info($component_id, $links)
	{
		$ret_array = array("Link" => array(
								'attri' => 'value',
								'databind' => "ln_".$component_id."_link"
								));
								
		$param_keys = array_keys($links);
		
		foreach($param_keys as $param_key)
		{
			if(strpos($param_key, LinkComponent::$LINK_PARAM_PREFIX) !== false)
			{
				$temp_array = array($param_key => array(
								'attri' => 'value',
								'databind' => "ln_".$component_id."_param_".$param_key));
				$ret_array = array_merge($ret_array, $temp_array);
			}
		}
		return $ret_array;
	}
}
?>